# Maintainer: Andrew Sun <adsun701@gmail.com>

_realname=zimg
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.0.1
pkgrel=1
pkgdesc="Scaling, colorspace conversion, and dithering library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://github.com/sekrit-twc/zimg"
license=("WTFPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "tar")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-winpthreads")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/sekrit-twc/${_realname}/archive/release-${pkgver}.tar.gz")
noextract=("${_realname}-${pkgver}.tar.gz")
sha256sums=('c50a0922f4adac4efad77427d13520ed89b8366eef0ef2fa379572951afcc73f')

prepare(){
  tar -xzvf "${srcdir}/${_realname}-${pkgver}.tar.gz"
  cd "${srcdir}/${_realname}-release-${pkgver}"
  ./autogen.sh
}

build() {
  [[ -d "build-${MINGW_CHOST}" ]] && rm -rf "build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  ../${_realname}-release-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install
}
